package com.cloudpivot.project.rabbitmq.controller;

import com.alibaba.fastjson2.JSONObject;
import com.cloudpivot.project.rabbitmq.service.MayCurContinueProducerService;
import com.cloudpivot.project.rabbitmq.service.MayCurDelayProducerService;
import com.cloudpivot.project.rabbitmq.service.MayCurProducerService;
import com.cloudpivot.project.rabbitmq.service.ProducerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/producerController")
public class FirstProducerController {
    @Autowired
    private ProducerService producerService;

    @Autowired
    private MayCurProducerService mayCurProducerService;

    @Autowired
    private MayCurDelayProducerService mayCurDelayProducerService;

    @Autowired
    private MayCurContinueProducerService mayCurContinueProducerService;

    @GetMapping("/sendMessage")
    @ResponseBody
    public String sendMessage(@RequestBody JSONObject entity,@RequestParam String key)
    {
        try {
//            System.out.println("message====>>" + JSONObject.toJSONString(entity));
            producerService.sendToRabbitMQHas(JSONObject.toJSONString(entity) ,key);
            return "Success";
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("/sendMessageToMaycur")
    @ResponseBody
    public String sendMessageToMaycur(@RequestBody JSONObject entity,@RequestParam String key)
    {
        try {
//            System.out.println("message====>>" + JSONObject.toJSONString(entity));
            mayCurProducerService.sendMaycurToRabbitMQ(JSONObject.toJSONString(entity) ,key);
            return "Success";
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("/sendMessageToDelayMaycur")
    @ResponseBody
    public String sendMessageToDelayMaycur(@RequestBody JSONObject entity)
    {
        try {
            mayCurDelayProducerService.sendDelayMaycurToRabbitMQ(JSONObject.toJSONString(entity));
            return "Success";
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("/sendMessageToContinueMaycur")
    @ResponseBody
    public String sendMessageToContinueMaycur(@RequestBody JSONObject entity)
    {
        try {
            mayCurContinueProducerService.sendContinueMaycurToRabbitMQ(JSONObject.toJSONString(entity));
            return "Success";
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
